package com.yxq.mdt.app.modules.video.model;

import com.yxq.mdt.app.base.ibase.IBaseModel;
import com.yxq.mdt.app.modules.publish.ui.bean.PublishListBean;
import com.yxq.mdt.app.modules.video.bean.AdvertBean;
import com.yxq.mdt.app.modules.video.bean.ChannelListBean;
import com.yxq.mdt.app.modules.video.bean.MLUserList;
import com.yxq.mdt.app.net.ApiModel;
import com.yxq.mdt.app.net.BaseObserver;
import com.yxq.mdt.app.net.RetrofitFactory;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class MainVideoModel implements IBaseModel {

    public static void getChannelConfig(int configType,ApiModel.CommonCallback<List<ChannelListBean>> callback) {
        RetrofitFactory.getJavaRetrofit().create(MainVideoApi.class)
                .getChannelConfig(configType)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<List<ChannelListBean>>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(List<ChannelListBean> respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    public void getMlList(int pageNum, int pageSize, int queryType, String mlChannel, String lng, String lat, ApiModel.CommonCallback<MLUserList> callback) {
        RetrofitFactory.getJavaRetrofit().create(MainVideoApi.class)
                .getMlList(pageNum, pageSize, queryType, mlChannel, lng, lat)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<MLUserList>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(MLUserList respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    public void advertByPosition(String position, ApiModel.CommonCallback<AdvertBean> callback) {
        RetrofitFactory.getJavaRetrofit().create(MainVideoApi.class)
                .advertByPosition(position)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<AdvertBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(AdvertBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    @Override
    public void onDestroy() {

    }
}
